using System;
using System.Net;

namespace FastSocket.Server
{
    /// <summary>
    /// udp session
    /// </summary>
    public sealed class UdpSession
    {
        /// <summary>
        /// udp server
        /// </summary>
        private readonly IUdpServer _server = null;
        /// <summary>
        /// get remote endPoint
        /// </summary>
        public readonly EndPoint RemoteEndPoint = null;
        
        /// <summary>
        /// new
        /// </summary>
        /// <param name="remoteEndPoint"></param>
        /// <param name="server"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public UdpSession(EndPoint remoteEndPoint, IUdpServer server)
        {
            if (server == null) throw new ArgumentNullException("server");
            this.RemoteEndPoint = remoteEndPoint;
            this._server = server;
        }
        
        /// <summary>
        /// send async
        /// </summary>
        /// <param name="payload"></param>
        public void SendAsync(byte[] payload)
        {
            this._server.SendTo(this.RemoteEndPoint, payload);
        }
    }
}